﻿@{
    ViewBag.Title = "返修品入库";//返修品入库 
    Layout = "~/Views/Shared/FrameWorkList.cshtml";
}

<script>
    var rowData = {};
    var index = -1;
    var FAccountDate=@ViewBag.FAccountDate;
    $(function () {
        initControl();
        gridList1();
    });
    function initControl() {
        $('select').bindSelect();
        //切换
        $('.category').on("click", function () {
            var aa = $("input[type='radio'].category:checked").val();
            if (aa == '登记') {
                gridList1();
            }
            else {
                gridList2();
            }
        });
        //来料单位
        $("#txtqueryFProCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
            id: "UnitNO",
            text: "UnitNOShortName"
        });
        //台帐日期赋初值
        $("#txtqueryFAccountDate").val(FAccountDate);
    }

    function gridList1() {
        $("#grid1").show();
        $("#grid2").hide();
        $(".rsider .active").show();
        $(".rsider .arc_show").hide();
        var $gridList = $("#gridList1");
        $gridList.dataGridForJson({
            url: "/VBaseData/V_CPK_42_MX_StoCPKListAcco/GetGridJson?keyword=CX",//入库主界面显示
            height: $(window).height() - 130,
            colModel: [
                    { label: "id", name: "FDocuListID", width: 120, align: 'center', hidden: true },
                    { label: '<input id="selectAll" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
                    { label: '单据编号', name: 'FDocuNO', width: 150, align: 'left' },
                    //{ label: '单据编号', name: 'FDouBarCode', width: 120, align: 'center' },
                    { label: '单据日期', name: 'FCurDate', width: 80, align: 'center' },

                    { label: "来料单位", name: "FProCompanyNO", width: 80, align: 'left' },
                    { label: "来料单位名称", name: "FProCompanyName", width: 120, align: 'left' },
                    { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left' },
                    { label: '零件名称', name: 'FProductionName', width: 140, align: 'left' },

                    { label: '开票数量', name: 'FQuantity_KP', width: 60, align: 'right' },
                    { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },
                    { label: '零件单价(元)', name: 'FPrice_KP', width: 80, align: 'right' },
                    { label: '金额(元)', name: 'FAmount_KP', width: 60, align: 'right' },
                    { label: '批次号', name: 'FBatchNo', width: 140, align: 'left' },

                    { label: '托盘编号', name: 'FPalletNO', width: 60, align: 'center' },
                    { label: '托盘数量', name: 'FPalletQuantity', width: 60, align: 'right' },
                    { label: '实际容量', name: 'FContainerNO', width: 60, align: 'right' },
                    { label: '标准容量', name: 'FContainerQuantity', width: 60, align: 'right' },
                    { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
                    { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
                    { label: '容器数量', name: 'FContainerQuantity', width: 60, align: 'right' },
                    { label: '标准装箱数', name: 'FContent', width: 70, align: 'right' },
                    { label: '实际装箱数', name: 'FFactContent', width: 70, align: 'right' },

                    { label: '开票总数', name: 'FQuantity_KP', width: 60, align: 'right' },
                    { label: '实际总数', name: 'FQuantity', width: 60, align: 'right' },
                    { label: '开票总价(元)', name: 'FAmount_KP', width: 80, align: 'right' },
                    { label: '实际总价(元)', name: 'FAmount', width: 80, align: 'right' },
                    { label: '凭证编号', name: 'FCredence', width: 80, align: 'left' },

                    { label: '备注', name: 'FDescription', width: 80, align: 'left' },
                    { label: '供货单位', name: 'FProductionTypeNO', width: 80, align: 'left' },
                    { label: '供货单位名称', name: 'FProductionTypeName', width: 100, align: 'left' },
                    { label: '零件分类', name: 'FState', width: 60, align: 'left' },
                    { label: '仓库编号', name: 'FStoreNO', width: 60, align: 'left' },

                    { label: '仓库名称', name: 'FStoreName', width: 80, align: 'left' },
                    { label: '定置编号', name: 'FStoreSetNO', width: 80, align: 'left' },

                    { label: '来料单位', name: 'FSupplierNO', width: 80, align: 'left' },
                    { label: '来料单位名称', name: 'FSupplierName', width: 100, align: 'left' },
                    { label: '入库单号', name: 'FSourceDouNO', width: 80, align: 'left' },
                    { label: '送检单号', name: 'FCheckBillCode', width: 80, align: 'left' },


                    { label: '输入人员', name: 'FUpdateBy', width: 60, align: 'left' },
                    { label: '输入日期', name: 'FUpdateDate', width: 80, align: 'center' },
                    { label: '输入时间', name: 'FUpdateTime', width: 60, align: 'center' },

                    { label: '审核人', name: 'FAuditingBy', width: 80, align: 'left' },
                    { label: '审核日期', name: 'FAuditingDate', width: 80, align: 'center' },
                    { label: '审核时间', name: 'FAuditingTime', width: 60, align: 'center' },
            ],
            pager: "#gridPager1",
            sortname: 'FDocuNO desc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                index = rowId;
                $.each(rowData, function (key, value) {
                    $("#txt" + key).val(value);
                });
            }
        });
        $("#selectAll").click(function (e) {
            $("input[name='checkbox']").prop("checked", this.checked);
            e.stopPropagation();
        });
    }

    function gridList2() {
        $("#grid1").hide();
        $("#grid2").show();
        $(".rsider .active").hide();
        $(".rsider .arc_show").show();
        var $gridList = $("#gridList2");
        var url="/VBaseData/V_CPK_45_HZ_StoCPKListAcco_Mid/GetParameterGridJson";
        var queryFAccountDate=$("#txtqueryFAccountDate").val();
        if( queryFAccountDate!=FAccountDate){
            url="/VBaseData/V_CPK_48_HZ_StoCPKListAcco_Arc/GetParameterGridJson";
        }
        $gridList.dataGrid({
            url: url,//入库主界面显示
            height: $(window).height() - 130,
            colModel: [
                    { label: "id", name: "FDocuListID", width: 120, align: 'center', hidden: true },
                    { label: '<input id="selectAll" type="checkbox" style="text-align:center;">', width: 60, align: 'center', sortable: false, formatter: $.checkbox, unformat: $.empty },
                    { label: '单据编号', name: 'FDocuNO', width: 150, align: 'center' },
                    { label: '单据日期', name: 'FCurDate', width: 80, align: 'left' },
                    { label: "来料单位", name: "FProCompanyNO", width: 80, align: 'left' },
                    { label: "来料单位名称", name: "FProCompanyName", width: 120, align: 'left' },
                    { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left' },
                    { label: '零件名称', name: 'FProductionName', width: 140, align: 'left' },
                    { label: '开票数量', name: 'FQuantity_KP', width: 60, align: 'right' },
                    { label: '实际数量', name: 'FQuantity', width: 80, align: 'right' },
                    { label: '零件单价(元)', name: 'FPrice_KP', width: 80, align: 'right' },
                    { label: '金额(元)', name: 'FAmount_KP', width: 60, align: 'right' },
                    { label: '批次号', name: 'FBatchNo', width: 140, align: 'left' },

                    { label: '托盘编号', name: 'FPalletNO', width: 60, align: 'center' },
                    { label: '托盘数量', name: 'FPalletQuantity', width: 60, align: 'right' },
                    { label: '实际容量', name: 'FContainerNO', width: 60, align: 'right' },
                    { label: '标准容量', name: 'FContainerQuantity', width: 60, align: 'right' },
                    { label: '容器编号', name: 'FContainerNO', width: 80, align: 'left' },
                    { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
                    { label: '容器数量', name: 'FContainerQuantity', width: 60, align: 'right' },
                    { label: '标准装箱数', name: 'FContent', width: 70, align: 'right' },
                    { label: '实际装箱数', name: 'FFactContent', width: 70, align: 'right' },

                    { label: '开票总数', name: 'FQuantity_KP', width: 60, align: 'right' },
                    { label: '实际总数', name: 'FQuantity', width: 60, align: 'right' },
                    { label: '开票总价(元)', name: 'FAmount_KP', width: 80, align: 'right' },
                    { label: '实际总价(元)', name: 'FAmount', width: 80, align: 'right' },
                    { label: '凭证编号', name: 'FCredence', width: 80, align: 'left' },

                    { label: '备注', name: 'FDescription', width: 80, align: 'left' },
                    { label: '供货单位', name: 'FProductionTypeNO', width: 80, align: 'left' },
                    { label: '供货单位名称', name: 'FProductionTypeName', width: 100, align: 'left' },
                    { label: '零件分类', name: 'FState', width: 60, align: 'left' },
                    { label: '仓库编号', name: 'FStoreNO', width: 60, align: 'left' },

                    { label: '仓库名称', name: 'FStoreName', width: 80, align: 'left' },
                    { label: '定置编号', name: 'FStoreSetNO', width: 80, align: 'left' },

                    { label: '来料单位', name: 'FSupplierNO', width: 80, align: 'left' },
                    { label: '来料单位名称', name: 'FSupplierName', width: 100, align: 'left' },
                    { label: '入库单号', name: 'FSourceDouNO', width: 80, align: 'left' },
                    { label: '送检单号', name: 'FCheckBillCode', width: 80, align: 'left' },

                    { label: '输入人员', name: 'FUpdateBy', width: 60, align: 'left' },
                    { label: '输入日期', name: 'FUpdateDate', width: 80, align: 'center' },
                    { label: '输入时间', name: 'FUpdateTime', width: 60, align: 'center' },

                    { label: '审核人', name: 'FAuditingBy', width: 80, align: 'left' },
                    { label: '审核日期', name: 'FAuditingDate', width: 80, align: 'center' },
                    { label: '审核时间', name: 'FAuditingTime', width: 60, align: 'center' },
            ],
            pager: "#gridPager2",
            sortname: 'UseUnit asc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                index = rowId;
                $.each(rowData, function (key, value) {
                    $("#txt" + key).val(value);
                });
            }
        });
    }

    function btn_Search() {

        var aa = $("input[type='radio'].category:checked").val();
        if (aa == '登记') {
            gridListSearch($("#gridList1"));
        }
        else {
            gridListSearch($("#gridList2"));
        }
    }

    function gridListSearch(obj) {
        obj.jqGrid('setGridParam', {  //companyname,productionno, fcurdate,   fvoucherno,   ledgerdate
            postData: {
                companyname: $("#txt_FProCompanyNO").val(), productionno: $("#ZSJ_B1_GH_SI").val(),
                fcurdate: $("#txt_FCurDate").val(), fvoucherno: $("#txt_FVoucherNo").val(), ledgerdate: $("#txt_FLedgerDate").val()
            },
        }).trigger('reloadGrid');
    }

    function btn_Ok() {
        $.each(rowData, function (key, value) {
            rowData[key] = $("#txt" + key).val();
        });
        $("#gridList1").jqGrid('setRowData', index, rowData);
    }
    function btn_Add() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/EnterWareHouse/WareHouseReturnRemainInput"
        });
    }

    function btn_Del() {
        var postData = $("#gridList1").jqGridRowValue().FDocuListID;
        $.deleteForm({
            url: "/WareHouse/EnterWareHouse/DeleteEB_StoRegister",
            param: { keyValue: postData },
            success: function () {
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function btn_Audit() {
        var dataArray = [];
        $("#gridList1 input:checkbox:checked").each(function () {
            var rowid = $(this).attr("value");
            dataArray.push($("#gridList1").jqGrid('getRowData', rowid).FDocuNO);
        });
        $.submitForm({
            url: "/WareHouse/EnterWareHouse/AuditReturnRemainStoreItem",
            param: { datas: JSON.stringify(dataArray) },
            success: function () {
                $("#gridList1").resetSelection();
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function btn_Delete() {
        var postData = [];
        $("#gridList1 input:checkbox:checked").each(function () {
            var rowid = $(this).attr("value");
            postData.push($("#gridList1").jqGrid('getRowData', rowid).FDocuListID);
        });
        $.deleteForm({
            url: "/WareHouse/EnterWareHouse/DeleteReturnRemainStoreItem",
            param: { datas: JSON.stringify(postData) },
            success: function () {
                $("#gridList1").trigger("reloadGrid");
            }
        })
    }

    function btn_Excel() {
        $.detailOpen({
            id: "Detail",
            title: "",
            url: "/WareHouse/Export/WareHouseNoticeExcel"
        });
    }
    //返修品入库打印
    function btn_Print() {
        var dataArray = [];
        var flag = "reg";
        var aa = $("input[type='radio'].category:checked").val();
        if (aa == '登记') {
            $("#gridList1 input:checkbox:checked").each(function () {
                var rowid = $(this).attr("value");
                dataArray.push($("#gridList1").jqGrid('getRowData', rowid).FRegisterID);
            });
        } else {
            $("#gridList2 input:checkbox:checked").each(function () {
                var rowid = $(this).attr("value");
                dataArray.push($("#gridList2").jqGrid('getRowData', rowid).FRegisterID);
            });
            flag = "arc";//档案
        };
        if (dataArray.length<=0) {
            $.modalMsg("请选择打印数据", "error");
            return false;
        }
        $.detailOpen({
            id: "PrintStorgeCard",
            title: "",
            url: "/WareHouse/EnterWareHouse/PrintStockReturnRemain?flag=" + flag + "&data=" + dataArray.join(',')
        });
    }
</script>

<div><input id="txtFDocuListID" name="FDocuListID" type="hidden" /></div>
<div class="functionHeader" style="width:100%;text-align:left;margin:0px;margin-top:0px;margin-bottom:0px; border-bottom:2px solid #CCC;">
    <div class="lsider">
        <div class="updowninput btn-group" style="margin-top:10px;">
            <input id="radio11" class="category" name="category" value="登记" checked="checked" type="radio"><label for="radio11" class="suffix">登记</label><br>
            <input id="radio12" class="category" name="category" value="档案" type="radio"><label for="radio12" class="suffix">档案</label>
        </div>
        <div class="updowninput" style="width:180px;height:20px;margin-left:10px;">
            <p>来料单位</p>
            <select id="txtqueryFProCompanyNO" name="F_DutyId" class="form-control">
                <option value="">==请选择==</option>
            </select>
        </div>
        <div class="updowninput">
            <p>零件编号</p>
            <input id="txtqueryFProductionNO"  type="text" class="form-control required" />
            &nbsp;
        </div>
        <div class="updowninput" style="width:120px;height:20px;margin-left:10px;">
            <p>来料日期</p>
            <input id="txtqueryFCurDate" type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker()" />
            &nbsp;
        </div>
        <div class="updowninput">
            <p>凭证编号</p>
            <input id="txtqueryFVoucherNo" name="FVoucherNo" type="text" class="form-control required" value="" />
            &nbsp;
        </div>
        <div class="updowninput" style="width:100px;margin-left:10px;">
            <p>台账日期</p>
            <input id="txtqueryFAccountDate"  type="text" class="form-control required input-wdatepicker" onfocus="WdatePicker({ dateFmt: 'yyyy-MM', isShowToday: false, isShowClear: false });" />
            &nbsp;
        </div>
        <div class="btn-group" style="margin-top:12px;margin-left:10px;">
            &nbsp;
            <a class="btn btn-primary center-block" onclick="btn_Search()"><span class="glyphicon glyphicon-search"></span>  &nbsp; 查询</a>
        </div>
    </div>

    <div class="rsider">
        <div class="btn-group" style="float:right;margin-top:12px;">
            <a class="btn btn-primary center-block" onclick="$.reload()">  <span class="glyphicon glyphicon-refresh"> </span>&nbsp刷新</a>
            <a class="btn btn-primary center-block active" onclick="btn_Add()">   <span class="glyphicon glyphicon-plus">    </span>&nbsp输入</a>
            <a class="btn btn-primary center-block active" onclick="btn_Del()">   <span class="glyphicon glyphicon-plus">    </span>&nbsp删除</a>
            <a class="btn btn-primary center-block active" onclick="btn_Modi()">  <span class="glyphicon glyphicon-plus">    </span>&nbsp修改</a>
            <a class="btn btn-primary center-block active" onclick="btn_Audit()">  <span class="glyphicon glyphicon-plus">    </span>&nbsp审核</a>
            <a class="btn btn-primary center-block active" onclick="btn_List()">  <span class="glyphicon glyphicon-th-list">    </span>&nbsp单据</a>
            <a class="btn btn-primary center-block arc_show" style="display:none;" onclick="btn_WriteOff()">  <span class="glyphicon glyphicon-th-list"></span>&nbsp冲红</a>
            <a class="btn btn-primary center-block" onclick="btn_Excel()"> <span class="glyphicon glyphicon-download"></span>&nbsp导出</a>
            <a class="btn btn-primary center-block" onclick="btn_Print()"> <span class="glyphicon glyphicon-print">   </span>&nbsp打印</a>
        </div>
    </div>
</div>
<div id="grid1">
    <table id="gridList1"></table>
    <div id="gridPager1"></div>
</div>
<div id="grid2">
    <table id="gridList2"></table>
    <div id="gridPager2"></div>
</div>



